home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / utils / switcher.lzh / NBRSS.C < prev    next >
C/C++ Source or Header  |  1990-04-04  |  3KB  |  97 lines

  1. #include <tos.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <mydefs.h>
  6.  
  7. char buf[4096];
  8. char spath[128];
  9. char fpath[128];
  10. char files[128][14];
  11. long fleng[128],l;
  12.  
  13. static char *sext  = "\\*.SND";
  14. static char *slash = "\\\0";
  15. static char *crlf = "\015\012";
  16.  
  17. long getline(
  18.         char    *dest,
  19.         char    *buf,
  20.         long    start,
  21.         long    max)
  22.         {
  23.         long p,q;
  24.         
  25.         q = 0L;
  26.         p = start;
  27.         while((p<max)&&(*(buf+p)<0x20))
  28.                 ++p;
  29.         while((p<max)&&(*(buf+p)>0x1f))
  30.                 {
  31.                 *(dest+q)=*(buf+p);
  32.                 ++p;
  33.                 ++q;
  34.                 }
  35.         *(dest+q) = 0;
  36.         return(p);
  37.         }
  38.  
  39. void main(void)
  40.         {
  41.         int fd;
  42.         DTA *d;
  43.         unt u;
  44.         uln     r;
  45.  
  46.         puts("NBRSS V1.0 - with Turbo C 2.0");
  47.         puts("NewBell Random Sound Selector");
  48.         puts("BY Gregory Mathias Lemperle-Kerr");
  49.  
  50.         if (Fsfirst("NEWBELL.DAT",0)>=0)
  51.                 {
  52.                 d=Fgetdta();
  53.                 l=d->d_length;
  54.                 puts("Using NEWBELL.DAT for paths...");
  55.                 fd=Fopen("NEWBELL.DAT",1);
  56.                 Fread(fd,l,buf);
  57.                 Fclose(fd);
  58.                 getline(spath,buf,0,l);
  59.                 }
  60.         else
  61.                 strcpy(spath,"C:\AUTO\SOUNDS\DEFAULT.SND");
  62.         for(r=strlen(spath);r>0;r--)
  63.                 if (*(spath+r)=='\\')
  64.                         break;
  65.         *(spath+r)=0;
  66.         strcpy(fpath,spath);
  67.         strcat(spath,sext);
  68.         puts(spath);
  69.         u = 0;
  70.         if ((fd=Fsfirst(spath,0))>=0) while (fd>=0)
  71.                 {
  72.                 d=Fgetdta();
  73.                 strncpy(files[u],d->d_fname,14);
  74.                 fleng[u]=d->d_length;
  75.                 fd = Fsnext();
  76.                 ++u;
  77.                 }
  78.         else
  79.                 {
  80.                 puts("NO DIGITIZED SOUND FILES FOUND!\007");
  81.                 return;
  82.                 }
  83.         r=(Random()+Gettime())%u;
  84.         puts(files[r]);
  85.         puts("Writing...");
  86.         if(Fsfirst("NEWBELL.DAT",0)>=0)
  87.                 Fdelete("NEWBELL.DAT");
  88.         strcat(fpath,slash);
  89.         strcat(fpath,files[r]);
  90.         strcat(fpath,crlf);
  91.         fd=Fcreate("NEWBELL.DAT",0);
  92.         Fclose(fd);
  93.         fd=Fopen("NEWBELL.DAT",WRITE);
  94.         Fwrite(fd,strlen(fpath),fpath);
  95.         Fclose(fd);
  96.         }
  97.